import {BrowserWindow, shell, TouchBar} from "electron";
import {exportHosts, importHosts, showMessageInMain} from "./utils";
import {MessageType, refreshDNS} from "../common/utils";

const {TouchBarButton} = TouchBar;


export default function setTouchBar(win: BrowserWindow) {
    const btnImport = new TouchBarButton({
        label: "📥 导入",
        click: () => importHosts(win)
    });
    const btnExport = new TouchBarButton({
        label: "📤 导出",
        click: () => exportHosts(win)
    });
    const btnRefreshDNS = new TouchBarButton({
        label: "🔗 刷新DNS",
        click: () => {
            refreshDNS()
                .then(res => showMessageInMain(res, MessageType.success))
                .catch(err => showMessageInMain(err, MessageType.error))
        }
    });
    const btnHelp = new TouchBarButton({
        label: "📖 帮助",
        click: () => shell.openExternal("https://gitee.com/iamhefang/mhosts/wikis/Home")
    })

    const touchBar = new TouchBar({
        items: [
            btnImport,
            btnExport,
            btnRefreshDNS,
            btnHelp
        ]
    });
    win.setTouchBar(touchBar);
};
